In [1]:
import sympy

import adaptive_trapezint as p1
import sinesum1 as p2
import centered_diff as p3
import find_primes as p4

Homework 1

Austin Ayers

2/12/2016

Excercises Completed:

Exercise 3.8 (adaptive_trapezint.py)
Exercise 3.15 (sinesum1.py)
Exercise 3.18 (centered_diff.py)
Exercise 3.20 (find_primes.py)

Adaptive trapezint

Program that takes takes a function an approximates its integral using the trapezoidal rule. As well, the program uses a varying n (number of subdivisions) to acquire a certain accuracy.

In [2]:
p1.outputInformation()


Function	Error			Estimated n
Cos [0,Pi]	0.00226972593728	508.367284751
Sin [0,Pi]	8.94076871116e-06	508.367284751
Sin [0,Pi/2]	0.00642962323093	508.367284751

Sine Summation

Program that compares a piecewise function: See 2.png
and the function that can approximate it: See 1.png

In [3]:
p2.outputTable()


n	alpha		Value of S		Value of f	Value of f - S



1	0.01	0.0795270998917		1		0.920472900108
1	0.25	-0.424413181578		1		1.42441318158
1	0.49	0.0795270998917		1		0.920472900108


3	0.01	0.235663207245		1		0.764336792755
3	0.25	-0.351656636165		1		1.35165663616
3	0.49	0.235663207245		1		0.764336792755


5	0.01	0.385248413145		1		0.614751586855
5	0.25	-0.32593462516		1		1.32593462516
5	0.49	0.385248413145		1		0.614751586855


10	0.01	0.711980829915		1		0.288019170085
10	0.25	-0.244361467333		1		1.24436146733
10	0.49	0.711980829915		1		0.288019170085


30	0.01	1.05156392494		1		-0.0515639249442
30	0.25	-0.262974151619		1		1.26297415162
30	0.49	1.05156392494		1		-0.0515639249442


100	0.01	0.870356367282		1		0.129643632718
100	0.25	-0.270088038931		1		1.27008803893
100	0.49	0.870356367282		1		0.129643632718

Centered Diff

Approximates a derivative of a function f(x) using an approximation formula

In [4]:
p3.application()


error of e^x @ (x=0): 1.66667499921e-05
error of e^(-2x^2) @ (x=0): 0.0
error of cos(x) @ (x=2pi): 0
error of ln(x) @ (x=1): 1.00003333533348

Find Prime Numbers

Uses the Sieve of Eratostenes to produce prime numbers

In [5]:
p4.output()


2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71

In [ ]: